﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MISAPP.MISInterface;

public partial class View_CIB_CIB002_1 : ViewMatrix
{
    int monthCount = 0;
    string[] months = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        criteriaList = new string[] { "Criteria", "ExclusiveOfAccount", "Unit"
            , "RMGroup","RM_GROUP" };
        serviceName = "MISAPP.Classify.Service.Service_CIB002";
        btn2Excel.PageParameter = "method=GetSummaryData&xls=CIB002&service=Service_CIB002";
        
        if (!IsPostBack)
        {
            GetData();
        }        
    }

    /// <summary>
    /// 計算出選了多少個月份，在Gridview中用來替換掉原本的cell
    /// </summary>
    /// <returns></returns>
    protected int GetMonthCount()
    {
        System.Collections.ArrayList al = Session["criteriaList"] 
            as System.Collections.ArrayList;
        List<iSelectList> criteriaList = al[0] as List<iSelectList>;
        iSelectList SL = criteriaList[0] as iSelectList;
        monthCount = SL.GetListCount();
        months = SL.GetListArray();
        return 0;
    }

    protected void GetData()
    {
        System.Data.DataTable dt = GetDataFromSerevice("GetSummaryData");
        GetMonthCount();
        CLB_Summary.SetData(dt, new string[] { });
    }

    protected void btn2Excel_Click(object sender, EventArgs e)
    {
        FillToSession();
    }

    protected void previous_click(object sender, EventArgs e)
    {
        //Session.Clear();  
        Utility.SessionClear();
    }

    #region GridView Method
    protected void CLB_RowDataBound(object sender, GridViewRowEventArgs e)
    { 
        //在這替換掉，某一些column 中的東西
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //string urlString = "../view/CIB/CIB002_2.aspx?rowIndex={0}&yyyymm={1}";
            //int x = 0;
            //for (int i = 1; i <= monthCount; i++)
            //{
            //    x = i * 3 - 1; //目前要取代第三個欄位，
            //    HyperLink link = new HyperLink();                
            //    link.Text = e.Row.Cells[x].Text;
            //    if (!e.Row.Cells[x].Text.Equals("&nbsp;"))
            //    {
            //        link.NavigateUrl = string.Format(urlString
            //            , e.Row.RowIndex.ToString()
            //            , months[i - 1]
            //            );
            //        e.Row.Cells[x].Controls.Add(link);                
            //    }
            //}        
        }
    }

   
    #endregion
}
